#ifndef REPORTGENERATOR_H
#define REPORTGENERATOR_H

#include <QObject>

#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QFileDialog>
#include <QPdfWriter>
#include <QPainter>
#include <QTextDocument>
//#include <QChartView>
//#include <QPieSeries>
//#include <QBarSeries>
//#include <QBarSet>
//#include <QLegend>
#include <QTextTable>
#include <QFontMetrics>
#include <QRandomGenerator>
#include <QDebug>

#include <QDate>
#include <QTextDocument>
#include <QTextTable>
#include <QTextFrame>
class ReportGenerator : public QObject {
    Q_OBJECT

public:
    explicit ReportGenerator(QObject *parent = nullptr);
private:
    int m_nYPos;
    int sizeText;           //普通正文 文本
    int sizeTitle1;         //一级标题
    int sizeTitle2;         //二级标题
    int emptyLine1;         //空格间隔行
    int legend1;            //图例

    QFont subtitleFont;
    QFont titleFont;
    QFont title2Font;
    QFont defaultFont;

    QPdfWriter* m_pPdfWritet;
    int m_nCurPageMaxY;
    int m_nCurPageMaxWidht;
    QPainter* m_pPainter;
    int m_nCurPageCount;

    //存放日志生成的pdf的图片
    QList<QPixmap> m_logImages;
public slots:
    void generateReport(const QString &filename);
    QList<QPixmap> outPreview();
private:
    void drawReportHeader(QPainter &painter, const QRect &rect);

    void drawSummaryAndCharts(QPainter &painter, const QRect &rect);

    void drawPieChart(QPainter &painter, int x, int y, int size);

    void drawBarChart(QPainter &painter, int x, int y, int width, int height);
    void drawTestResultsTable(QPainter &painter, const QRect &rect, QPdfWriter &writer);

    void drawEnvironmentInfo(QPainter &painter, const QRect &rect);

    void drawConclusion(QPainter &painter, const QRect &rect);

    //判断是否需要进行新pdf页的新增
    void addPage(int pos,int height);
    void drawTextOnPdf(int x,int w,int h,QString text ,Qt::AlignmentFlag flag = Qt::AlignLeft,bool autoMove = true);
    void drawSubTitle();
    void outParamInit();

    void drawSampleTable(QPainter &painter, const QRect &area);

    //绘制全部内容
    void drawInfo(QPainter* painter,QRect pageRect);
};
#endif // REPORTGENERATOR_H
